
//
// Created by kaifamiao on 2022/3/19.
//
#include <iostream>
#include <vector>
#include<io.h>
#include <string.h>
#include<algorithm> //for_each
using namespace std;
#ifndef READ_CSV_PUBLIC_H
#define READ_CSV_PUBLIC_H

#endif //READ_CSV_PUBLIC_H
#define BLACK "\033[0m\033[1;30m"
#define RED "\033[0m\033[1;31m"
#define GREEN "\033[0m\033[1;32m"
#define YELLOW "\033[0m\033[1;33m"
#define BLUE "\033[0m\033[1;34m"
#define PINK "\033[0m\033[1;35m"
#define CYAN "\033[0m\033[1;36m"
#include <ctime>

void printl(const char *) {};

template <typename T, typename... Types>
void printl(char const *color,const T& firstArg, const Types&... args)
{
    //cout << firstArg ;
    //char* s1="\033[0m\033[1;31m";
    cout << color <<firstArg<<"\033[0m" ;//[0m[1;
    printl(color,args...);
}
void log(const char *) {};
template <typename TT, typename... Typess>
void log(const TT& firstArg, const Typess&... args)
{
    cout <<firstArg  ;
    log(args...);
}
void printv(vector<string> v_files){

    for_each(v_files.begin(), v_files.end(), [](string val)->void {  cout << val << endl;});
    printl(YELLOW,"this vector size:",v_files.size(),"\n");

}
typedef int FuncType(int,int); //定义了FuncType这种函数数据类型
int exec(FuncType p,int a,int b)
{
    printl(BLUE,"exec()","\n");
    time_t begin,end;
    double ret;
    begin=clock();
    int r =p(a,b);
//    cout <<"return p("<<a<<","<<b<<"),result="<<r<<endl;
    end=clock();
    ret=double(end-begin)/CLOCKS_PER_SEC;
    printl(BLUE,"runtime:",ret,"\n");
    return 0;
}
//C++ 获取文件夹下的所有文件名
vector<string>  getFiles( const string& path) {
    //文件句柄
    long hFile;
    //文件信息
    struct _finddata_t fileinfo{};
    vector<string> files;
    string p;
    if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) {
        do {
            //如果是目录,迭代之
            //如果不是,加入列表
            if ((fileinfo.attrib & _A_SUBDIR)) {
                if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
                    getFiles(p.assign(path).append("\\").append(fileinfo.name));
            } else {
                files.push_back(p.assign(path).append("\\").append(fileinfo.name));
            }
        } while (_findnext(hFile, &fileinfo) == 0);
        _findclose(hFile);
    }
    return files;
}

vector<string> getFiles(string path,string exteName)
{

    vector<string> files;
    char *to_search;        //欲查找的文件，支持通配符
    path=path+exteName;
    strcpy(to_search,path.c_str());//用到 c_str()函数
    long handle;                                                //用于查找的句柄
    struct _finddata_t fileinfo;                          //文件信息的结构体
    handle=_findfirst(to_search,&fileinfo);         //第一次查找
    if(-1==handle)
        files.push_back("NODATA");;
    ///printf("%s\n",fileinfo.name);                         //打印出找到的文件的文件名
    files.push_back(fileinfo.name);
    while(!_findnext(handle,&fileinfo))               //循环查找其他符合的文件，知道找不到其他的为止
    {
        files.push_back(fileinfo.name);
        //printf("%s\n",fileinfo.name);
    }
    _findclose(handle);                                      //别忘了关闭句柄
    return files;
}
vector<string> getAllFiles( string path)
{
    //文件句柄
    vector<string> files;
    long  hFile  =  0;
    //文件信息
    struct _finddata_t fileinfo;
    string p;
    if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1)
    {
        do
        {
            if((fileinfo.attrib & _A_SUBDIR))
            {
                if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
                {
                    files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
                    getAllFiles( p.assign(path).append("\\").append(fileinfo.name) );
                }
            }
            else
            {
                files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
            }
        }while(_findnext(hFile, &fileinfo) == 0);
        _findclose(hFile);
        return files;
    }
}